//
//  XYUtils.h
//  PeiJue
//
//  Created by lxy on 2017/9/21.
//  Copyright © 2017年 lixiya. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger,Authorization) {
    AuthorizationTakePhoto = 0,
    AuthorizationPhoto = 1,
    AuthorizationAudio = 2,
    AuthorizationLocation = 3,
};

@interface XYUtils : NSObject

/** NSString信息存储 */
+(void)setUserDefault:(NSString *)key byValue:(id)value;
+(void)deleteUserDefault:(NSString *)key;
+(id)getUserDefault:(NSString *)key;

/** 保存int */
+(void)setInt:(NSInteger)i key:(NSString *)key;

/** 读取int */
+(NSInteger)intForKey:(NSString *)key;

/** 保存float */
+(void)setFloat:(CGFloat)floatValue key:(NSString *)key;

/** 读取float */
+(CGFloat)floatForKey:(NSString *)key;

/** 保存bool */
+(void)setBool:(BOOL)boolValue key:(NSString *)key;

/** 读取bool */
+(BOOL)boolForKey:(NSString *)key;


/** string->json */
+ (id)getObjectFromJsonString:(NSString *)jsonString;
/** json->string */
+ (NSString *)getJsonStringFromObject:(id)object;

/** 获取本地plist文件 */
+ (NSArray *)getArrayFromPlist:(NSString *)plistName;

/** 获取Caches目录 */
+ (NSString *)getDownloadFilePath:(NSString *)filename;


/** 删除本被文件 */
+ (void)removeFileAtPath:(NSString *)filePath;
/** 文件地址是否存在 */
+ (BOOL)isFileExitsAtPath:(NSString *)filePath;

/** 单个文件的大小 */
+ (long long) fileSizeAtPath:(NSString*) filePath;
/** 遍历文件夹获得文件夹大小，返回多少M */
+ (float ) folderSizeAtPath:(NSString*) folderPath;


/** NSDate互转NSString */
+ (NSDate *)NSStringToDate:(NSString *)dateString;
+ (NSDate *)NSStringToDate:(NSString *)dateString withFormat:(NSString *)formatestr;
+ (NSString *)NSDateToString:(NSDate *)dateFromString withFormat:(NSString *)formatestr;

#pragma mark - 如何通过一个整型的变量来控制数值保留的小数点位数。以往我们通类似@"%.2f"来指定保留2位小数位，现在我想通过一个变量来控制保留的位数
+ (NSString *)newFloat:(float)value withNumber:(int)numberOfPlace;

#pragma mark - 使用subString去除float后面无效的0
+ (NSString *)changeFloatWithString:(NSString *)stringFloat;

#pragma mark - 去除float后面无效的0
+ (NSString *)changeFloatWithFloat:(CGFloat)floatValue;

#pragma mark - 字符串类型判断
+ (BOOL)isPureInt:(NSString*)string;
+ (BOOL)isPureFloat:(NSString*)string;


#pragma mark -  计算两个时间相差多少秒
+ (NSInteger)getSecondsWithBeginDate:(NSString*)currentDateString  AndEndDate:(NSString*)tomDateString;


/** 获取系统的各种权限 */
+ (BOOL)handleWithAuthWith:(Authorization)Authorization;

/** 判断手机号是否合法 */
+ (BOOL)isValidateMobile:(NSString *)mobile;
/** 验证是否是邮箱 */
+ (BOOL)validateEmail:(NSString *)email;


#pragma mark - UIAlertController提示框 可根据需求定制弹出框文本颜色
/** 在当前ViewController上弹出提示框 只有确定按钮*/
+ (void)showMessageWithViewController:(UIViewController *)vc title:(NSString *)title message:(NSString *)message confirmTitle:(NSString *)confirmTitle confirmHandler:(void(^)(UIAlertAction *action))confirmhandler;

/** 在当前Window上弹出提示框 只有确定按钮*/
+ (void)showMessageWithTitle:(NSString *)title message:(NSString *)message confirmTitle:(NSString *)confirmTitle confirmHandler:(void(^)(UIAlertAction *action))confirmhandler;

/** 在当前ViewController上弹出提示框 只有确定和取消按钮*/
+ (void)showMessageWithViewController:(UIViewController *)vc title:(NSString *)title message:(NSString *)message confirmTitle:(NSString *)confirmTitle cancleTitle:(NSString *)cancleTitle confirmHandler:(void(^)(UIAlertAction *action))confirmhandler cancleHandler:(void(^)(UIAlertAction *action))cancleHandler;

/** 在当前Window上弹出提示框 只有确定和取消按钮*/
+ (void)showMessageWithTitle:(NSString *)title message:(NSString *)message confirmTitle:(NSString *)confirmTitle cancleTitle:(NSString *)cancleTitle confirmHandler:(void(^)(UIAlertAction *action))confirmhandler cancleHandler:(void(^)(UIAlertAction *action))cancleHandler;

@end
